"""
File: utils.py
Author: ershixiong
Date: 2023/12/20
describe:

"""
import csv
import json
import os

import yaml


def get_yaml(path):
    """

    :param path:
    :return: [[-0.01, 0.02, 0.01],[-0.01, 0.02, 0.01]] 格式数据
    """
    with open(path, 'r', encoding='utf-8') as f:
        yaml_data = yaml.safe_load(f)
        # print(yaml_data)
        # for i in yaml_data:
        #     print(type(i),i)
        return yaml_data


def get_csv(path):
    """
    :param path:
    :return: [[-0.01, 0.02, 0.01],[-0.01, 0.02, 0.01]] 格式数据
    """
    with open(path, 'r', encoding='utf-8') as f:
        raws = csv.reader(f)
        csv_data = []

        for raw in raws:
            print(raw)
            origin_type_data = []
            for i in raw:
                origin_type_data.append(convert_to_origin_type(i))
            csv_data.append(origin_type_data)
    return csv_data


def get_json(path):
    """

    :param path:
    :return: [[-0.01, 0.02, 0.01],[-0.01, 0.02, 0.01]] 格式数据
    """
    with open(path, 'r', encoding='utf-8') as f:
        dict_datas = json.load(f)
        # print(dict_datas)
        result_list = [value for value in dict_datas.values()]
        # print(result_list)

    return result_list


def get_root_path():
    path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    return path


def convert_to_origin_type(value):
    try:
        return int(value)
    except:
        try:
            return float(value)
        except:
            return value